
//
//  SystemMacro.h
//  KKZone
//
//  Created by  CarlsonLee on 2018/9/17.
//  Copyright © 2018年 YANJING. All rights reserved.
// 通用的一些系统配置

#ifndef SystemMacro_h
#define SystemMacro_h

#ifdef __cplusplus
#define EXTERN_C_BEGIN  extern "C" {
#define EXTERN_C_END  }
#else
#define EXTERN_C_BEGIN
#define EXTERN_C_END
#endif

EXTERN_C_BEGIN

#pragma mark - #系统配置
///屏幕大小
#ifndef kScreen
#define kScreen [UIScreen mainScreen].bounds.size
#endif

///屏幕Scale
#ifndef kScreenScale
#define kScreenScale [UIScreen mainScreen].scale
#endif

///视图bound
#ifndef kBounds
#define kBounds  self.bounds.size
#endif

#ifndef kScaleX
#define kScaleX   kScreen.width/375
#endif

///log
#ifndef _DevLog
#ifdef DEBUG
#define _DevLog(...) NSLog(@"%s 第%d行 \n %@\n\n",__func__,__LINE__,[NSString stringWithFormat:__VA_ARGS__])
#else
#define _DevLog(...) do { } while (0)
#endif
#endif

#ifndef weakify
#if DEBUG
#if __has_feature(objc_arc)
#define weakify(object)  __weak __typeof__(object) weak##_##object = object;
#else
#define weakify(object)  __block __typeof__(object) block##_##object = object;
#endif
#else
#if __has_feature(objc_arc)
#define weakify(object) @try{} @finally{} {} __weak __typeof__(object) weak##_##object = object;
#else
#define weakify(object) @try{} @finally{} {} __block __typeof__(object) block##_##object = object;
#endif
#endif
#endif

#ifndef strongify
#if DEBUG
#if __has_feature(objc_arc)
#define strongify(object) autoreleasepool{} __typeof__(object) object = weak##_##object; if (!object) return;
#else
#define strongify(object) autoreleasepool{} __typeof__(object) object = block##_##object; if (!object) return;
#endif
#else
#if __has_feature(objc_arc)
#define strongify(object) @try{} @finally{} __typeof__(object) object = weak##_##object; if (!object) return;
#else
#define strongify(object) @try{} @finally{} __typeof__(object) object = block##_##object; if (!object) return;
#endif
#endif
#endif

//适配iOS11--contentInsetAdjustmentBehavior
#define AdjustsScrollViewInsetNever(controller,view) if(@available(iOS 11.0, *)) {view.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;} else if([controller isKindOfClass:[UIViewController class]]) {controller.automaticallyAdjustsScrollViewInsets = false;}

///判断刘海屏
#define IS_IPHONEX \
({BOOL isPhoneX = NO;\
if (@available(iOS 11.0, *)) {\
isPhoneX = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom > 0.0;\
}\
(isPhoneX);})
///系统版本
#define IPHONE_VERSION(x) ([[UIDevice currentDevice] systemVersion].floatValue >= x)
///广播
#define XN_NOTIFICATION_CENTER [NSNotificationCenter defaultCenter]
///userDefaults
#define XN_USERDEFAULTS [NSUserDefaults standardUserDefaults]
///url
#define XN_URL(_str_) [NSURL URLWithString:_str_]
///图片
#define XN_IMG(_name_) [UIImage imageNamed:_name_]
///加载Bundle图片
#define XN_RIMG(_name_) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:_name_ ofType:nil]]
///error init
#define XN_ERROR(error_reason, error_code) [NSError errorWithDomain:error_reason code:error_code userInfo:nil]

#ifndef GEL_SWAP
#define GEL_SWAP(a, b)  do { __typeof__(a) _tmp_ = (a); (a) = (b); (b) = _tmp_; } while (0)
#endif

///颜色
#ifndef ColorFromRGB
#define ColorFromRGB(_rgbValue_) [UIColor \
colorWithRed:((float)((_rgbValue_ & 0xFF0000) >> 16))/255.0 \
green:((float)((_rgbValue_ & 0xFF00) >> 8))/255.0 \
blue:((float)(_rgbValue_ & 0xFF))/255.0 alpha:1.0]
#endif

#ifndef ColorFromRGBA
#define ColorFromRGBA(_rgbValue_, _alpha_) [UIColor \
colorWithRed:((float)((_rgbValue_ & 0xFF0000) >> 16))/255.0 \
green:((float)((_rgbValue_ & 0xFF00) >> 8))/255.0 \
blue:((float)(_rgbValue_ & 0xFF))/255.0 alpha:_alpha_]
#endif

/**
 单例
 Synthesize a sharedInstace.
 */
#ifndef GEL_SHARED_INSTANCE
#define GEL_SHARED_INSTANCE() \
static id sharedInstance = nil; \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
sharedInstance  = [[[self class] alloc] init]; \
}); \
return sharedInstance;
#endif

EXTERN_C_END

#endif
